
package ro.qi.framework.sys.security.entities;

import java.util.Date;

import ro.qi.framework.sys.debug.Logger;
import ro.qi.framework.sys.entities.Entity;

public class SecurityApplication extends Entity {
	
	public SecurityApplication() {
		super();
	}

	public SecurityApplication(int id) {
		super();
		setId(id);
		select();
	}

	public SecurityApplication(String code) {
		super();
		setCode(code);
		select();
	}

	public void setId(int value) {
		setValue("id", value);
	}

	public int getId() {
		return getIntValue("id");
	}

	public void setCode(String value) {
		setValue("code", value);
	}

	public String getCode() {
		return getStringValue("code");
	}

	public void setCategoryId(int value) {
		setValue("categoryId", value);
	}

	public int getCategoryId() {
		return getIntValue("categoryId");
	}

	public void setName(String value) {
		setValue("name", value);
	}

	public String getName() {
		return getStringValue("name");
	}

	public void setJavaClass(String value) {
		setValue("class", value);
	}

	public String getJavaClass() {
		return getStringValue("class");
	}

	public void setDescription(String value) {
		setValue("description", value);
	}

	public String getDescription() {
		return getStringValue("description");
	}

	public Date getCreatedTime() {
		return getDateValue("createdTime");
	}

	public Date getUpdatedTime() {
		return getDateValue("updatedTime");
	}

	public Object getInstance() {
		Object instance = null;
		if (getJavaClass() != null && getJavaClass().length() > 0) {
			try {
				instance = Class.forName(getJavaClass()).newInstance();
			} catch (InstantiationException e) {
				//Logger.error(this, "Class " + javaClass + " could not be instantied: " + e.getMessage());
			} catch (IllegalAccessException e) {
				//Logger.error(this, "Class " + javaClass + " not accesible: " + e.getMessage());
			} catch (ClassNotFoundException e) {
				Logger.error(this, "Class " + getJavaClass() + " not found: " + e.getMessage());
			} catch (ClassCastException e) {
				Logger.error(this, "Class " + getJavaClass() + " not an AdministrationPage: " + e.getMessage());
			}
		}
		return instance;
	}

//	private int id = 0;
//	private String category = "";
//	private String name = "";
//	private String javaClass = "";
//
//	public Application(int id, String category, String name, String javaClass) {
//		this.id = id;
//		this.name = name;
//		this.javaClass = javaClass;
//		this.category = category;
//	}
//
//	public int getId() {
//		return id;
//	}
//
//	public String getJavaClass() {
//		return javaClass;
//	}
//
//	public String getCategory() {
//		return category;
//	}
//
//	public String getName() {
//		return name;
//	}
//

}
